package cn.tedu.supermarket.types.controller;

import cn.tedu.supermarket.base.response.JsonResult;
import cn.tedu.supermarket.types.pojo.dto.TypesQuery;
import cn.tedu.supermarket.types.pojo.dto.TypesSaveParam;
import cn.tedu.supermarket.types.pojo.vo.TypesVO;
import cn.tedu.supermarket.types.service.TypesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/types")
public class TypesController {
    @Autowired
    private TypesService typesService;
    @GetMapping("select")
    public JsonResult selectTypes(TypesQuery typesQuery){
        log.debug("查询分类信息:{}", typesQuery);
        List<TypesVO> list = typesService.selectTypes(typesQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveTypes(TypesSaveParam typesVO){
        log.debug("保存分类信息:{}", typesVO);
        typesService.saveTypes(typesVO);
        return JsonResult.ok();
    }

    @PostMapping("/delete/typeId/{typeId}")
    public JsonResult deleteTypes(@PathVariable Long typeId){
        log.debug("删除分类信息:{}", typeId);
        typesService.deleteTypes(typeId);
        return JsonResult.ok();
    }
}
